package com.dz51.core.proxy;  

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.StatementCallback;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
  
public class JdbcTemplateProxy { 
	
	private TemplateContainer slaveTemplateContainer = null;
	private TemplateContainer masterTemplateContainer = null;
	
	public JdbcTemplateProxy(SlaveTemplateContainer slaveTemplateContainer, MasterTemplateContainer masterTemplateContainer) {
		super();
		this.slaveTemplateContainer = slaveTemplateContainer;
		this.masterTemplateContainer = masterTemplateContainer;
	}
	
	public JdbcTemplate getMasterJdbcTemplate(){
		return this.masterTemplateContainer.getJdbcTemplate();
	}
	
	public JdbcTemplate getSlaveJdbcTemplate(){
		return this.slaveTemplateContainer.getJdbcTemplate();
	}
	
	/** ------------------------ batchUpdate ，使用master数据源  ------------------------------**/
	public int[] batchUpdate(String sql, BatchPreparedStatementSetter pss) throws DataAccessException {
		return this.getMasterJdbcTemplate().batchUpdate(sql, pss);
	}
	public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss) {
		return this.getMasterJdbcTemplate().batchUpdate(sql, batchArgs, batchSize, pss);
	}
	public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) {
		return this.getMasterJdbcTemplate().batchUpdate(sql, batchArgs, argTypes);
	}
	public int[] batchUpdate(String sql, List<Object[]> batchArgs) {
		return this.getMasterJdbcTemplate().batchUpdate(sql, batchArgs);
	}
	public int[] batchUpdate(String[] sql) throws DataAccessException {
		return this.getMasterJdbcTemplate().batchUpdate(sql);
	}
	/** ------------------------ batchUpdate ，使用master数据源  ------------------------------**/
	
	/** ------------------------ excute ，使用master数据源  ------------------------------**/
	public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters)
			throws DataAccessException {
		return this.getMasterJdbcTemplate().call(csc, declaredParameters);
	}
	public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(csc, action);
	}
	public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(action);
	}
	public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(psc, action);
	}
	public <T> T execute(StatementCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(action);
	}
	public <T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(callString, action);
	}
	public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
		return this.getMasterJdbcTemplate().execute(sql, action);
	}
	public void execute(String sql) throws DataAccessException {
		this.getMasterJdbcTemplate().execute(sql);
	}
	/** ------------------------ excute ，使用master数据源  ------------------------------**/
	
	/** ------------------------ query ，使用slave数据源  ------------------------------**/
	public <T> T query(PreparedStatementCreator psc, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(psc, pss, rse);
	}
	public <T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(psc, rse);
	}
	public void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(psc, rch);
	}
	public <T> List<T> query(PreparedStatementCreator psc, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(psc, rowMapper);
	}
	public <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, args, argTypes, rse);
	}
	public void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(sql, args, argTypes, rch);
	}
	public <T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, args, argTypes, rowMapper);
	}
	public <T> T query(String sql, Object[] args, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, args, rse);
	}
	public void query(String sql, Object[] args, RowCallbackHandler rch) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(sql, args, rch);
	}
	public <T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, args, rowMapper);
	}
	public <T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, pss, rse);
	}
	public void query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(sql, pss, rch);
	}
	public <T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, pss, rowMapper);
	}
	public <T> T query(String sql, ResultSetExtractor<T> rse, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, rse, args);
	}
	public <T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, rse);
	}
	public void query(String sql, RowCallbackHandler rch, Object... args) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(sql, rch, args);
	}
	public void query(String sql, RowCallbackHandler rch) throws DataAccessException {
		this.getSlaveJdbcTemplate().query(sql, rch);
	}
	public <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, rowMapper, args);
	}
	public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().query(sql, rowMapper);
	}
	public int queryForInt(String sql, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForInt(sql, args);
	}
	public int queryForInt(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForInt(sql, args, argTypes);
	}
	public int queryForInt(String sql) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForInt(sql);
	}
	public <T> List<T> queryForList(String sql, Class<T> elementType, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, elementType, args);
	}
	public <T> List<T> queryForList(String sql, Class<T> elementType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, elementType);
	}
	public List<Map<String, Object>> queryForList(String sql, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, args);
	}
	public <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, args, elementType);
	}
	public <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, args, argTypes, elementType);
	}
	public List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql, args, argTypes);
	}
	public List<Map<String, Object>> queryForList(String sql) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForList(sql);
	}
	public long queryForLong(String sql, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForLong(sql, args);
	}
	public long queryForLong(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForLong(sql, args, argTypes);
	}
	public long queryForLong(String sql) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForLong(sql);
	}
	public Map<String, Object> queryForMap(String sql, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForMap(sql, args);
	}
	public Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForMap(sql, args, argTypes);
	}
	public Map<String, Object> queryForMap(String sql) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForMap(sql);
	}
	public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, requiredType, args);
	}
	public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, requiredType);
	}
	public <T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, args, requiredType);
	}
	public <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, args, argTypes, requiredType);
	}
	public <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, args, argTypes, rowMapper);
	}
	public <T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, args, rowMapper);
	}
	public <T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, rowMapper, args);
	}
	public <T> T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForObject(sql, rowMapper);
	}
	public SqlRowSet queryForRowSet(String sql, Object... args) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForRowSet(sql, args);
	}
	public SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForRowSet(sql, args, argTypes);
	}
	public SqlRowSet queryForRowSet(String sql) throws DataAccessException {
		return this.getSlaveJdbcTemplate().queryForRowSet(sql);
	}
	/** ------------------------ query ，使用slave数据源  ------------------------------**/
	
	/** ------------------------ update ，使用master数据源  ------------------------------**/
	public int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(psc, generatedKeyHolder);
	}
	public int update(PreparedStatementCreator psc) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(psc);
	}
	public int update(String sql, Object... args) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(sql, args);
	}
	public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(sql, args, argTypes);
	}
	public int update(String sql, PreparedStatementSetter pss) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(sql, pss);
	}
	public int update(String sql) throws DataAccessException {
		return this.getMasterJdbcTemplate().update(sql);
	}
	/** ------------------------ update ，使用master数据源  ------------------------------**/
}
